<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>8_3_1-定义过度动画-2-animation</title>
</head>

<body>


    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <style>
        @keyframes keyframes-in {
            from {
                width: 0px;
                height: 0px;
                background-color: red;
            }

            to {
                width: 100px;
                height: 100px;
                background-color: blue;
            }
        }

        @keyframes keyframes-out {
            from {
                width: 100px;
                height: 100px;
                background-color: blue;
            }

            to {
                width: 0px;
                height: 0px;
                background-color: red;
            }
        }

        /*默认样式*/
        .demo {
            width: 100px;
            height: 100px;
            background-color: rgb(207, 106, 11);
        }

        .ani-enter-from {
            width: 0px;
            height: 0px;
            background-color: red;
        }

        .ani-enter-active {
            animation: keyframes-in 3s;
        }

        .ani-enter-to {
            width: 100px;
            height: 100px;
            background-color: blue;
        }

        .ani-leave-from {
            width: 100px;
            height: 100px;
            background-color: blue;
        }

        .ani-leave-active {
            animation: keyframes-out 3s;
        }

        .ani-leave-to {
            width: 0px;
            height: 0px;
            background-color: red;
        }
    </style>
    <div id="Application">
        <button @click="click">显示/隐藏</button>
        <transition name="ani">
            <div v-if="show" class="demo"></div>
        </transition>
    </div>
    <script>
        const App = Vue.createApp({
            data() {
                return {
                    show: false
                }
            },
            methods: {
                click() {
                    this.show = !this.show
                }
            }
        })
        App.mount("#Application")
    </script>
</body>

</html>